/**
 * 
 */
package com.xidian.zhiancloud.service.file.impl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.xidian.zhiancloud.service.file.FileService;
import com.xidian.zhiancloud.util.tools.FileUploadUtils;

/**
 * @author zwt
 *
 * 2021年3月9日
 */
@Service
public class LocalFileServiceImpl implements FileService {
	 /**
     * 资源映射路径 前缀
     */
    @Value("${file.prefix}")
    public String localFilePrefix;

    /**
     * 域名或本机访问地址
     */
    @Value("${file.domain}")
    public String domain;
    
    /**
     * 上传文件存储在本地的根路径
     */
    @Value("${file.path}")
    private String localFilePath;
    
	@Override
	public String uploadFile(MultipartFile file, String folder) throws Exception {
		// TODO Auto-generated method stub
		// 上传并返回访问地址
    	if(folder !=null && !folder.equals("")) {
    		localFilePath =localFilePath+"/"+folder;
    		localFilePrefix =localFilePrefix+"/"+folder;
    	}
		String name = FileUploadUtils.upload(localFilePath, file);
		
        String url = domain + localFilePrefix + name;
        return url;
	}

}
